package com.hmdp.ThreadUtil;

import lombok.extern.slf4j.Slf4j;

/**
 *@Author:fengxiaohui
 *@Description:
 *@Date:Create in 3:53 下午 2023/6/5
 *@Modified By:
 */
@Slf4j
public class TwoPhaseTermination {
    private Thread t1;

    public static void main(String[] args) throws InterruptedException {
        TwoPhaseTermination twoPhaseTermination = new TwoPhaseTermination();
        twoPhaseTermination.start();
        Thread.sleep(3500);
        twoPhaseTermination.stop();

    }

    private void start(){

        t1 = new Thread(()->{
            while(true) {
                boolean interrupted = Thread.currentThread().isInterrupted();
                if (interrupted) {
                    log.debug("料理后事");
                    break;
                }
                try {
                    Thread.sleep(1000);
                    log.debug("执行监控");
                } catch (InterruptedException e) {

                    e.printStackTrace();
                    Thread.currentThread().interrupt();
                }
            }
            });
        t1.start();

        }
    private void stop(){
        t1.interrupt();
    }
}
